


var web = $(".list-wrap"),
	ul = $(".list-wrap ul"),
	lis = $(".list-wrap ul li"),
	btnLeft = $(".left"),
	btnRight = $(".right");


var imgObj = null;
var imgId = getUrlParam('id');
$.ajax({
	type: "post",
	url: "http://m2.t1.laisj.com/publics/cantonfair/getposter",
	async: false,
	data: {
		id: getUrlParam('id')
	},
	success: function(res) { //成功得到返回时运行
		if(res.code == 200) {
			imgObj = res;
		}
	},
	ajaxError: function(a, b, c) {
		console.log(a); //错误的对象
		console.log(b); //错误的类型
		console.log(c); //错误的信息
	},
});



var $img = $('.list-wrap img');
var imgsrc = imgObj.msg;
for(var i = 0;i<imgsrc.length;i++){
	$img.eq(i).attr('src',imgsrc[i]);
}

var selindex = 0;
var indexImg = null;
var swiper = new Swiper('.swiper-container', {
	loop:true,
	prevButton:'.carousel-wrap .left',
	nextButton:'.carousel-wrap .right',
	pagination : '.swiper-pagination',
	paginationType : 'custom',
  	paginationCustomRender: function (swiper, current, total) {
        wxShare(current-1);
        return indexImg = current;
  	}
});





//放大图片
var onOff = true;
$('#web .list-wrap').click(function() {
	var url = $('.list-wrap li').eq(indexImg).children().attr('src');
	$('.win-imgwrap img').attr('src',url);
	$('.win-imgwrap').css('transform','scale(1,1)');
});

$('.win-imgwrap').click(function(){
	$('.win-imgwrap').css('transform','scale(0,0)');
});

$('.win-imgwrap').on('touchstart',function(e){
	e.stopPropagation(); 
});








var $sharemoment = $('#web .sharemoments'),
//	$sharefriend = $('#web .sharefriend'),
	$alertview   = $('#web .alert-view'),
	$wrap  =    $('#web');

//切换中英文
changeType();
function changeType(){
	if(getUrlParam('type')==0){
		$('title').html('我的产品-我的海报'); 
		
		$sharemoment.text('分享');
//		$sharefriend.text('分享给朋友');
		$alertview.text('点击查看大图，长按保存图片');
		
		$wrap.removeClass('active');
	}else{
		$('title').html('My product- My poster'); 
		
		$sharemoment.text('Share');
//		$sharefriend.text('Shared with friends');
		$alertview.text('Click to enlarge & Long press to save image');
		
		$wrap.addClass('active');
	}
}


//分享按钮事件
var $shareview = $('#web .share-wrap');
share($sharemoment);
//share($sharefriend);
function share($sel){
	$sel.click(function(){
		$shareview.fadeIn();
	});
}
$shareview.click(function(){
	$(this).fadeOut();	
});


//获取
wx.ready(function(){
	wxShare(selindex);
});
wx.error(function(res){
   console.log(res); 
});


function wxShare(selindex){
	var lanType = getUrlParam('type');
	var title = null,
	    ptext = null;
	if(lanType==0){
		title = '制作你的专属广交会海报';
		ptext = '赶快做一张海报，让大家看看您在广交会有多热门';
	}else{
		title = 'make your own Canton Fair poster';
		ptext = 'Let’s make a poster to show how hot your products are !';
	}
	wx.onMenuShareTimeline({
	    title: title,   // 分享标题
	    link: 'http://m2.t1.laisj.com/publics/image/'+imgId+'/'+selindex+'/'+lanType,     // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	    imgUrl: 'http://x1.t1.laisj.com/cantonfairH5/img/share.png', // 分享图标
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	        console.log('successShareTimeline',selindex);
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	    }
	});
	//分享给朋友
	wx.onMenuShareAppMessage({
	    title: title, // 分享标题
	    desc: ptext, // 分享描述
	    link: 'http://m2.t1.laisj.com/publics/image/'+imgId+'/'+selindex+'/'+lanType, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
	    imgUrl: 'http://x1.t1.laisj.com/cantonfairH5/img/share.png', // 分享图标
	    type: 'link', // 分享类型,music、video或link，不填默认为link
	    dataUrl: '', // 如果type是music或video，则要提供数据链接，默认为空
	    success: function () { 
	        // 用户确认分享后执行的回调函数
	        console.log('successShareAppMessage',selindex);
	    },
	    cancel: function () { 
	        // 用户取消分享后执行的回调函数
	    }
	});
}








//获取链接参数的方法
function getUrlParam(name){
	var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");  //构造一个含有目标参数的正则表达式对象
	var r = window.location.search.substr(1).match(reg);   //匹配目标参数
	//返回参数值
	if (r!=null){
		return unescape(r[2]);
	}else{
		return null;      
	}  
} 